<template>
	<view class="content">
			<view class="box1">
				<view class="box3">点击分享获得您的专属课表邀请码</view>
				
				<view class="box3">{{yaoqingma}}</view>
				<u-button class="box4" type="primary"  @click="putINOthers" >我要分享</u-button>
			</view>
			<view class= "word">
				小贴士：每次获得的专属邀请码只可分享给一人，分享后即失效，验证码十五分钟内有效。
			</view>
			<view class="box2">
				<view class="box6">在下框输入分享方给您的邀请码</view>
				<input class="box5" v-model="yaoqing"></input>
				<view class="box3"></view>
				<u-button class="box4" type="primary"@click="putInMine" >我要导入</u-button>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				xuehao:"",
				password:"",
				yaoqingma:"",
				yaoqing:"",
				it_list:[],
			
			}
		},
		methods: {
			putINOthers(){
				var xuehao = getApp().globalData.xuehao
				var password = getApp().globalData.userpassword
				var that = this;
					uni.showLoading({
						title: "加载中"
					})
					uni.request({
						url: getApp().globalData.URL + "friend/getyaoqing",
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							username: xuehao,
							userpassword: password,
							year:43,
							term:1
						// year term暂时固定为最新时间 即获取目前学期课表后续修改  year 计算方式为 当前年份 —— 1980 term 计算方式 春1 秋2
						},
						success(res) {
							console.log("yaoqing:", res);
							if (res.data.statusCode == 1000){
								that.yaoqingma = res.data.yaoqingma
								
								
								console.log(that.yaoqing)
								
								
								uni.showToast({
									title:"获取成功，请分享给你的好友",
									icon: 'success'
								})
								if (res.data.yaoqing.length == 0) {
									uni.showToast({
										title: "未能获取请1min后尝试",
										icon: 'none',
									})
								}
							} else {
								uni.showToast({
									title: '加载失败',
									icon: 'none'
								})
							}
						},
						fail(res) {
							console.log(res);
							uni.showToast({
								title: '路由失败',
								icon: 'none'
							})
						},
						complete() {
							uni.hideLoading();
						}
					})
				
			},
			// 拿到邀请码的其他用户可以接受到分享者的课表数据
			putInMine() {
				var that = this;
				var xuehao = getApp().globalData.xuehao
				console.log(that.yaoqing);
					uni.showLoading({
						title: "加载中"
					})
					uni.request({
						url: getApp().globalData.URL + "friend/fromyaoqingma",
						method: 'GET',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							yaoqingma:that.yaoqing,
							who: that.xuehao,
							
						
						},
						success(res) {
							console.log("itlist:", res);
							if (res.data.statusCode == 1000){
								that.it_list = res.data.kechengbiao
								
								
								uni.setStorageSync('otherclass', that.it_list)
								
								// 只允许单次看到单人
							
								
								console.log(that.it_list)
								
								
								uni.showToast({
									title: title,
									icon: 'success'
								})

								if (res.data.kechengbiao.length == 0) {
									uni.showToast({
										title: "未获取到课表",
										icon: 'none',
									})
								}
							} else {
								uni.showToast({
									title: '邀请码失效',
									icon: 'none'
								})
							}
						},
						fail(res) {
							console.log(res);
							uni.showToast({
								title: '路由失败',
								icon: 'none'
							})
						},
						complete() {
							uni.hideLoading();
						}
					})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		justify-content: center;
		flex-direction: column;
		background-color:#f7f1e3;
		padding-bottom: 100rpx;
	
	
	
	
	}
	.box1 {
		display: flex;
		justify-content: center;
		flex-direction: column;
		
	
		width: 80vw;
		height: 30vh;
		position: relative;
		left: 85rpx;
		line-height: 80rpx;
		margin-top: 40rpx;
		
	
	
		border-radius: 35px;
		background-color: rgba(255, 255, 255, 100);
	
		border: 1rpx solid rgba(187, 187, 187, 100);
		margin-bottom: 80rpx;

		
	}
	.box2 {
		display: flex;
		justify-content: center;
		flex-direction: column;
		margin-top: 80rpx;
			
		width: 80vw;
		height: 36vh;
		position: relative;
		left: 85rpx;
		line-height: 80rpx;
		
		
			
			
		border-radius: 35px;
		background-color: rgba(255, 255, 255, 100);
			
		border: 1rpx solid rgba(187, 187, 187, 100);
	}
	
	.box3 {
		
		
		width: 60vw;
		position: relative;
		left: 60rpx;
		margin-bottom: 40rpx;
		border-radius: 9px 9px 9px 9px;
		
		font-size: 30rpx;
		
		box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
		font-family: Arial;
		
		text-align: center;
		
	}
	.box4 {
		width: 28vw;
		position: relative;
		left: 70rpx;
		margin-left: 110rpx;
		border-radius: 9px 9px 9px 9px;
		
		text-align: left;
		box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
		font-family: Arial;
		
	}
	.box5{
		width: 70vw;
		position: relative;
		left: 34rpx;
		margin-bottom: 40rpx;
		border-radius: 9px 9px 9px 9px;
		
		font-size: 30rpx;
		
		box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
		font-family: Arial;
	}
	.box6 {
		width: 60vw;
		position: relative;
		left: 70rpx;
		margin-bottom: 40rpx;
		border-radius: 9px 9px 9px 9px;
		
		font-size: 30rpx;
		
		box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
		font-family: Arial;
		
		text-align: center;
	}
	.word{
		display: flex;
		flex-direction: center;
		justify-content: center;
		margin: 30rpx;
	}
</style>

